from flask import Blueprint, request
from utilsapp.mysql_con import db_insert, db_pagelist, db_delete


bluePrint = Blueprint("config", __name__)
tableName = "config"


# 分页查询
@bluePrint.route("/getlist", methods=["post"])
def table_list():
    sql = f"SELECT * from {tableName} "
    j = db_pagelist(sql, request.json["page"])
    return j


@bluePrint.route("/delete", methods=["post"])
def log_delete():
    id = request.json["id"]
    return db_delete(tableName, f"WHERE id=%s", {"id": id})


@bluePrint.route("/add", methods=["POST"])
def log_add():
    return db_insert(tableName, request.json)
